<?php
/* ===========================
 * * 文章类
 * @ by 子不语 爱不语CMS
 * @ QQ:76992327
 * @ Create:2014.04.6
  ============================ */
if (!defined('KKINC'))
    exit('Request Error!');

class ad {

    function __construct() {
        
    }
    function get_ad($str){
        $arr=array();
        parse_str($str,$arr);
        if($arr['show']>0){
            
        }else{
            switch ($arr['type']){
                
                case'text':                
                    return $this->get_text($arr['group']);
                    break;
                case'pic':                
                    return $this->get_pic($arr['group']);
                    break;
                case'url':                
                    return $this->get_url($arr['group']);
                    break;
                default :
                    return $this->get_one_ad($arr['group']);
                    break;
            }
        }
    }
     function get_list_ad($str) {
        $result =$arr= array();
        if (!is_array($str))
            parse_str(trim($str), $arr);
        if ($arr['start'] && $arr['show']) {
            $num = ' limit ' . (int) $arr['start'] . ',' . (int) $arr['show'];
        } else if ($arr['show']) {
            $num = ' limit ' . (int) $arr['show'];
        }
        if ($arr['orderby']) {
            $orderby = $arr['orderby'];
        } else {
            $orderby = 'id asc';
        }
        $res = db::_query('select * from __ads where `group`=\'' . $arr['group'] . '\' and is_show=1 order by '.$orderby.' '.$num);
        while ($oj = db::get_all($res)) {
            $result[] = $oj;
        }
        return $result;
    }
    function get_one_ad($group){
        return db::get_one('select * from __ads where `group`=\'' . $group . '\' and is_show=1');
    }
    function get_text($group){
        $result=  $this->get_one_ad($group);
        return $result->text;
    }
    function get_pic($group){
         $result=  $this->get_one_ad($group);
        return $result->pic;
    }
    function get_url($group){
         $result=  $this->get_one_ad($group);
        return $result->url;
    }
}
